﻿using ITSM.Model;
using ITSM.Model.Entity;
using ITSM.Model.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITSM.Service
{
    public class Company : BaseDB, ICompany
    {
        public List<RYD_Company> QueryCompany()
        {
            List<RYD_Company> result = new ();
            List< RYD_FieldDict> companyList = db.Queryable<RYD_FieldDict>().Where(res => res.RYD_FieldName == "Company" && res.RYD_State == 1).ToList();
            foreach (RYD_FieldDict item in companyList)
            {
                result.Add(new RYD_Company
                {
                    RYD_Id = item.RYD_Id,
                    RYD_CompanyNo=item.RYD_FieldValue,
                    RYD_CompanyName=item.RYD_FieldText
                }) ;
            }
            return result;
        }
        public bool SetCompany(RYD_UserCompany company)
        {
            RYD_UserInfo userinfo = new()
            {
                RYD_Id = company.RYD_UserId,
                RYD_Company = company.RYD_CompanyNo,
                RYD_ModifyBy = company.RYD_UserId,
                RYD_ModifyTime = DateTime.Now
            };
            if (db.Updateable(userinfo).UpdateColumns(res=>new { res.RYD_Company ,res.RYD_ModifyTime,res.RYD_ModifyBy}).ExecuteCommand()>0)
            {
                return true;
            }
            return false;
        }
    }
}
